﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;

using Db4objects.Db4o;
using Db4objects.Db4o.Config;
using Db4objects.Db4o.Query;
using Db4objects.Db4o.Events;

using System.Linq;
using Db4objects.Db4o.Linq;

using NLog;

using System.Text;
using System.IO;

using Layers;
using Layers.History;

namespace Layers.Tests
{
    using MbUnit.Framework;

    public class NoConv<K> : IConverter<K, K>
    {

        #region IConverter<long,long> Members

        public K Convert(K input)
        {
            return input;
        }

        #endregion
    }

    [TestFixture]
    public class HistoryTest : TestBase
    {
        [Test]
        public override void All()
        {
            Hist();
        }

        public void Hist()
        {
            Type T = typeof(Person);

            ClassMeta cmeta = new ClassMeta(T);

            IEnumerable<FieldMeta> members = cmeta.FilterMembers(
                delegate(FieldMeta mi)
                {
                    return mi.Type.IsValueType;
                });

            ColumnHistory<long, Person> hist = 
                new ColumnHistory<long, Person>(cmeta.Type, members, new NoConv<long>());

            IHistCursor<long, Person> cur = hist.GetCursor();

            cur.CurrentStamp = 1;
            cur.Insert();

            cur.Current = new Person("A");
            cur.MoveNext();

            IEnumerator<Person> cur2 = hist.GetEnumerator();
            while (cur2.MoveNext())
            {
                Person p = cur2.Current;
            }
        }
    }
}